﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
    
namespace TouchControls
{
    [TemplateVisualState(GroupName = "SelectionStates", Name = "Selected")]
    [TemplateVisualState(GroupName = "SelectionStates", Name = "Unselected")]
    [TemplateVisualState(GroupName = "SelectionStates", Name = "Inactive")]
    public class PivotHeader : ContentControl
    {
        public PivotItem Item { get; internal set; }

        public PivotHeader()
        {
            this.DefaultStyleKey = typeof(PivotHeader);
            MouseUp += new System.Windows.Input.MouseButtonEventHandler(PivotHeader_MouseUp);
        }

        void PivotHeader_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var pivot = this.FindParent<TouchPivot>();
            pivot.SelectedIndex = pivot.Items.IndexOf(this.Item);
        }        

        public void StateUnselected()
        {
            VisualStateManager.GoToState(this, "Unselected", false);
        }

        public void StateSelected()
        {
            VisualStateManager.GoToState(this, "Selected", false);
        }

        public void StateInactive()
        {
            VisualStateManager.GoToState(this, "Inactive", false);
        }
    }
}
